package dS.ProjectGPS.LeicaOWI;

import javax.microedition.lcdui.*;


public class FormOwi1SP_2DH extends Form implements FormOwi {

  OWIAgent owiAgent = null;

  TextField shiftY = new TextField("Shift dY (m)", "", 50, TextField.DECIMAL);
  TextField rotation = new TextField("Rotation (Sec of Arc)", "", 50,
                                     TextField.DECIMAL);
  TextField scale = new TextField("Scale", "", 50, TextField.DECIMAL);
  TextField shiftX = new TextField("Shift dX (m)", "", 50, TextField.DECIMAL);
  TextField rotationY = new TextField("Rotation Origin Y0 (m)", "", 50,
                                      TextField.DECIMAL);
  TextField rotationX = new TextField("Rotation Origin X0 (m)", "", 50,
                                      TextField.DECIMAL);

  public FormOwi1SP_2DH(OWIAgent o) {
    super("2D Helmet Transformation");

    owiAgent = o;

    try {
      ndsInit();
    }
    catch (Exception ex) {
    }
  }

  public void ndsInit() throws Exception {
    append(rotationX);
    append(rotationY);
    append(shiftX);
    append(shiftY);
    append(rotation);
    append(scale);
  }

  public void update() {
    owiAgent.query(OWI.qs1SP());

    rotationX.setString(OWI.osp2dhRotX);
    rotationY.setString(OWI.osp2dhRotY);
    shiftX.setString(OWI.osp2dhShiftX);
    shiftY.setString(OWI.osp2dhShiftY);
    rotation.setString(OWI.osp2dhRotation);
    scale.setString(OWI.osp2dhScale);
  }

  public void save() {

    String msgId = "1SP";

    // Setup SET parameters
    String[] outputs = {
                       msgId,
                       OWI.ospUtmFOEast,
                       OWI.ospUtmFONorth,
                       OWI.ospUtmLatOrigin,
                       OWI.ospUtmCentralMeridian,
                       OWI.ospUtmScale,

                       rotationX.getString(),
                       rotationY.getString(),
                       shiftX.getString(),
                       shiftY.getString(),
                       rotation.getString(),
                       scale.getString(),

                       OWI.ospHtOriginX,
                       OWI.ospHtOriginY,
                       OWI.ospHtP1,
                       OWI.ospHtP2,
                       OWI.ospHtP3
    };

    //Send message and update form if successful
    int ackCode = (owiAgent.set(msgId, OWI.setMessage(outputs)));
    Controller.showACKAlert(this,this,ackCode);


  }
}
